package com.gxg.kotlin.mydemo10

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.text.TextUtils
import android.view.View
import android.widget.Toast
import com.gxg.kotlin.mydemo10.activity.HomeActivity
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        tv_test.text  = "登陆"

        tv_login?.setOnClickListener{v: View ->
            login();
        }
    }

    fun login(){
        val username:String? = et_username.text.toString()
        val pwd:String? = et_pwd.text.toString()

        if (TextUtils.isEmpty(username) || TextUtils.isEmpty(pwd)) {
            toast("用户名或密码不能为空")
            return
        }
        startActivity(Intent(this, HomeActivity::class.java))
        toast(username+"  "+pwd,Toast.LENGTH_SHORT)

    }

    fun Activity.toast(message: CharSequence, duration: Int = Toast.LENGTH_SHORT) {
        Toast.makeText(this, message, duration).show()
    }
}
